﻿<navControls:Page x:Class="ExpenseReport.UpdateExpenseReport" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:navControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
    xmlns:data="clr-namespace:System.Windows.Data;assembly=System.Windows.Ria.Controls"
    xmlns:df="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm"
    xmlns:dg="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
    xmlns:ria="clr-namespace:System.Windows.Controls;assembly=System.Windows.Ria.Controls"      
    xmlns:er="clr-namespace:ExpenseReport"
    Width="Auto"
    Height="Auto"
    Title="DataFormFields Page">
    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.Resources>
            <ria:DomainDataSource x:Name="ods"
                             LoadMethodName="LoadExpenseReportWithDetails" 
                             Loaded="ods_Loaded"
                             LoadedData="ods_LoadedData"
                             AutoLoad="False"
                             >
                <ria:DomainDataSource.DomainContext>
                    <er:ExpenseData/>
                </ria:DomainDataSource.DomainContext>
            </ria:DomainDataSource>
        </Grid.Resources>
        <df:DataForm x:Name="expenseForm" AutoGenerateFields="False"
                               Width="Auto"
                               Header="Modify Expense Report"
                               >
            <df:DataForm.Fields>
                <df:DataFormFieldGroup Orientation="Horizontal">
                    <df:DataFormFieldGroup Orientation="Vertical">
                        <df:DataFormDateField Binding="{Binding Created, Mode=TwoWay, NotifyOnValidationError=true,  ValidatesOnExceptions=true}"/>
                        <df:DataFormTextField Binding="{Binding Company, Mode=TwoWay, NotifyOnValidationError=true,  ValidatesOnExceptions=true}"/>
                        <df:DataFormTextField Binding="{Binding Department, Mode=TwoWay, NotifyOnValidationError=true,  ValidatesOnExceptions=true}"/>
                    </df:DataFormFieldGroup>
                    <df:DataFormFieldGroup Orientation="Vertical">
                        <df:DataFormTemplateField FieldLabelPosition="Top" FieldLabelContent="Description">
                            <df:DataFormTemplateField.DisplayTemplate>
                                <DataTemplate>
                                    <TextBox Text="{Binding Description, Mode=TwoWay, NotifyOnValidationError=true,  ValidatesOnExceptions=true}"
                                         Height="100" IsEnabled="False"/>
                                </DataTemplate>
                            </df:DataFormTemplateField.DisplayTemplate>
                            <df:DataFormTemplateField.EditTemplate>
                                <DataTemplate>
                                    <TextBox Text="{Binding Description, Mode=TwoWay, NotifyOnValidationError=true,  ValidatesOnExceptions=true}" 
                                         Height="100"/>
                                </DataTemplate>
                            </df:DataFormTemplateField.EditTemplate>
                        </df:DataFormTemplateField>
                    </df:DataFormFieldGroup>
                </df:DataFormFieldGroup>
                <df:DataFormTemplateField FieldLabelPosition="Top" FieldLabelContent="Details">
                    <df:DataFormTemplateField.DisplayTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <dg:DataGrid ItemsSource="{Binding ExpenseReportDetails}" AutoGenerateColumns="False" 
                                             IsEnabled="False" Width="570" IsReadOnly="True">
                                    <dg:DataGrid.Columns>
                                        <dg:DataGridTextColumn Binding="{Binding DateIncurred}" Header="Date"/>
                                        <dg:DataGridTextColumn Binding="{Binding Amount}" Header="Amount"/>
                                        <dg:DataGridTextColumn Binding="{Binding ShortDescription}" Header="Summary"/>
                                    </dg:DataGrid.Columns>
                                </dg:DataGrid>
                                <StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Margin="10">
                                    <Button Content="Edit Entry" Width="90" Margin="10,0,0,0" IsEnabled="False" Click="btnEditClick"/>
                                    <Button Content="Add Entry" Width="90" Margin="10,0,0,0" IsEnabled="False" Click="btnAddClick"/>
                                    <Button Content="Delete Entry" Width="90" Margin="10,0,0,0" IsEnabled="False" Click="btnDeleteClick"/>
                                </StackPanel>
                            </StackPanel>
                        </DataTemplate>
                    </df:DataFormTemplateField.DisplayTemplate>
                    <df:DataFormTemplateField.EditTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <dg:DataGrid x:Name="editDetailsDataGrid" ItemsSource="{Binding ExpenseReportDetails}" AutoGenerateColumns="False" Width="570"
                                             SelectionChanged="editDetailsDataGrid_SelectionChanged"
                                             >
                                    <dg:DataGrid.Columns>
                                        <dg:DataGridTextColumn Binding="{Binding DateIncurred}" Header="Date"/>
                                        <dg:DataGridTextColumn Binding="{Binding Amount}" Header="Amount"/>
                                        <dg:DataGridTextColumn Binding="{Binding ShortDescription}" Header="Summary"/>
                                    </dg:DataGrid.Columns>
                                </dg:DataGrid>
                                <StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Margin="10">
                                    <Button Content="Edit Entry" Width="90" Margin="10,0,0,0" IsEnabled="True" Click="btnEditClick"/>
                                    <Button Content="Add Entry" Width="90" Margin="10,0,0,0" IsEnabled="True" Click="btnAddClick"/>
                                    <Button Content="Delete Entry" Width="90" Margin="10,0,0,0" IsEnabled="True" Click="btnDeleteClick"/>
                                </StackPanel>
                            </StackPanel>
                        </DataTemplate>
                    </df:DataFormTemplateField.EditTemplate>
                </df:DataFormTemplateField>
            </df:DataForm.Fields>

        </df:DataForm>

    </Grid>
</navControls:Page>
